package cn.gson.springboot.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.springboot.model.pojos.DestructionYk;
import cn.gson.springboot.model.pojos.FactoryYk;
import cn.gson.springboot.model.pojos.OutboundYk;
import cn.gson.springboot.model.pojos.ReturnDrugsYk;
import cn.gson.springboot.model.service.OutboundYkService;
import cn.gson.springboot.model.vo.ApplyVO;
import cn.gson.springboot.model.vo.DestructionYkVO;
import cn.gson.springboot.model.vo.OutboundYkVO;

@Controller
public class OutboundYkController {
	@Autowired
	private OutboundYkService obs;
	
	//出药房查询所有
	@RequestMapping("ckbiaoge")
	@ResponseBody
	public Map<String,Object> hosLikeTableSmt(
			@RequestParam("page")int page,
			@RequestParam("rows")int rows,Integer outbound_id){
		//进行分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		JSONArray findall=obs.findchuku(outbound_id);
			
		//进行数据格式转换和封装
		Map<String,Object> map = new HashMap<>();
		map.put("total", pg.getTotal());//封装总记录数
		map.put("rows", findall);//封装当前页的内容
			
		return map; 
	}	
	
	//修改销毁状态
	@PostMapping("ckxgztid")
	@ResponseBody
	public String idxx(Integer outboundId) {
		OutboundYk l = obs.idckxgzt(outboundId);
		if(l!=null) {
			l.setOutboundStatic("已成功");
			obs.adds(l);
			return "1";
		}else {
			return "0";
		}
	}
	
	//出药房详情查询所有
	@RequestMapping("chuyfxq")
	@ResponseBody
	public JSONArray findbycyfxqid(Integer outbound_id) {
		 JSONArray findbycyfxqid = obs.findbycyfxq(outbound_id);
		 System.out.println(findbycyfxqid.toString());
		 return findbycyfxqid;
	}
	
	//请领单详情
	@RequestMapping("qldxq")
	@ResponseBody
	public JSONArray qldxiangqing(Integer apply_id) {
		 JSONArray qldxiangqing = obs.qldxiangqing(apply_id);
		 System.out.println(qldxiangqing.toString());
		 return qldxiangqing;
	}
	
	//主从表新增
	@RequestMapping("shenqing-save")
	@ResponseBody
	public String saveOrder(OutboundYkVO purVo) {
		try {
			obs.saveOutbound(purVo);
			return "出库成功";
		} catch (Exception e) {
			e.printStackTrace();
			return "出库失败";
		}
	}
	
}
